﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
#if DOT_NET
using Microsoft.VisualStudio.TestTools.UnitTesting;
#else
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
#endif
using StyleMVVM.UnitTests.TestClasses.SimpleObjects;
using StyleMVVM.Utilities;

namespace StyleMVVM.UnitTests.Utilities
{
	[TestClass]
	public class SerializationHelperTests
	{
		[TestMethod]
		public void FileSerializeTest()
		{
			var task = Task.Run(new Func<Task>(AsyncFileSerialize));

			task.Wait(100000);
		}

		private async Task AsyncFileSerialize()
		{
			SerializeObject serializeObject =
				new SerializeObject
					{
						TestDouble = 123.456,
						TestInt = 987,
						TestString = "Hello Kitty"
					};

			await SerializationHelper.SerializeToFile("OutputFile.txt", serializeObject);

			SerializeObject deserializedObject = await SerializationHelper.DeserializeFromFile<SerializeObject>("OutputFile.txt");

			Assert.AreEqual(serializeObject.TestDouble, deserializedObject.TestDouble);
			Assert.AreEqual(serializeObject.TestInt, deserializedObject.TestInt);
			Assert.AreEqual(serializeObject.TestString, deserializedObject.TestString);
		}

		[TestMethod]
		public void CompressTest()
		{
			var task = Task.Run(new Func<Task>(AsyncCompresSerialize));

			task.Wait(100000);
		}

		private async Task AsyncCompresSerialize()
		{
			SerializeObject serializeObject =
				new SerializeObject
					{
						TestDouble = 123.456,
						TestInt = 987,
						TestString = "Hello Kitty"
					};

			await SerializationHelper.CompressToFile("CompressOutputFile.txt", serializeObject);

			SerializeObject deserializedObject =
				await SerializationHelper.DecompressFromFile<SerializeObject>("CompressOutputFile.txt");

			Assert.AreEqual(serializeObject.TestDouble, deserializedObject.TestDouble);
			Assert.AreEqual(serializeObject.TestInt, deserializedObject.TestInt);
			Assert.AreEqual(serializeObject.TestString, deserializedObject.TestString);
		}
	}
}